package com.zcp.controller;


import com.zcp.entity.address;
import com.zcp.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("address")
public class AddressController {
    @Autowired
    private AddressService addressService;

//    添加
    @RequestMapping("save")
    public String save(address address){
        addressService.save(address);
        return "redirect:/address/findAll";
    }



    @RequestMapping("findAll")
    public String findALL(Model model){
        List<address> addresses = addressService.findAll();
        model.addAttribute("address",addresses);
        return "back/address/index";
    }

    @GetMapping("change/{id}")
    public String change(@PathVariable("id") Integer id, Model model){
        address address = addressService.change(id);
        model.addAttribute("address",address);
        return "back/address/change";
    }

    @RequestMapping("changed")
    public String changed(address address){
        addressService.changed(address);
        return "redirect:/address/findAll";
    }
    @GetMapping("delete/{id}")
    public String delete(@PathVariable("id") Integer id){
        addressService.delete(id);
        return "redirect:/address/findAll";
    }

}
